package Clases;


import Clases.EntityDB.Credenciales;
import Clases.EntityDB.Estudiantes;
import Pruebas.KnockKnockProtocol;
import java.net.*;
import java.io.*;
import servidor.ebooker.Funciones.Login;

public class HiloManejadorClientes extends Thread {
    private Socket socket = null;
    private Estudiantes Estudiante;
    private Credenciales credencial;
    

    public HiloManejadorClientes(Socket socket) {
	this.socket = socket;
        System.out.println("Cliente "+this.socket.getInetAddress().getHostAddress()+" Aceptado.");
    }

    @Override
    public void run() {
	try {
	    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
	    BufferedReader in = new BufferedReader(new InputStreamReader(
                                        socket.getInputStream()));

	    String inputLine;
            String[] split;
            out.println("Conectado.");

	    while ((inputLine = in.readLine()) != null) {
                
                    split = inputLine.split(":");
                    
                    if(split[0].equals("close")){
                        break;
                    }
                    if(split[0].equals("login")){
                        credencial = Login.login(split[1],split[2]);
                        if(credencial!=null){
                            out.println("msg:Bienvenid@ "
                                +credencial.getEstudiantes().getNombre()
                                +" "+credencial.getEstudiantes().getPrimerApellido());
                            out.println("Bye.");
                        }else{
                            out.println("Datos incorrectos, Verifique.");
                        }
                            
                        
                        
                        
                    }
                    
                    
                    
                    
                    
                
	    }
	    out.close();
	    in.close();
	    socket.close();

	} catch (IOException e) {
	    e.printStackTrace();
	}
    }
}
